import 'package:flutter/material.dart';
import 'package:my_flutter/first/ui/page_web_view.dart';
import 'package:toast/toast.dart';

class ArticleItem extends StatefulWidget {
  final itemData;

  const ArticleItem(this.itemData, {super.key});

  @override
  State<ArticleItem> createState() => _ArticleItemState();
}

class _ArticleItemState extends State<ArticleItem> {
  double _scale = 1.0;

  @override
  Widget build(BuildContext context) {
    Row author = Row(
      children: [
        Expanded(
          child: Text.rich(
            TextSpan(
              children: [
                TextSpan(text: "作者: "),
                TextSpan(
                  text: widget.itemData['author'],
                  style: TextStyle(color: Theme.of(context).primaryColor),
                ),
              ],
            ),
          ),
        ),
        Text(widget.itemData['niceDate']),
      ],
    );

    Text title = Text(
      widget.itemData['title'],
      style: TextStyle(fontSize: 16.0, color: Colors.black),
      textAlign: TextAlign.left,
    );

    Text chapterName = Text(
      widget.itemData['chapterName'],
      style: TextStyle(color: Theme.of(context).primaryColor),
    );

    Column column = Column(
      //垂直线性布局
      crossAxisAlignment: CrossAxisAlignment.start, //子控件左对齐
      children: <Widget>[
        Padding(padding: EdgeInsets.all(10.0), child: author),
        Padding(
          padding: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
          child: title,
        ),
        Padding(
          padding: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 10.0),
          child: chapterName,
        ),
      ],
    );

    return InkWell(
      onTap: () {
        //Toast.show("author:${itemData['author']}");
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (BuildContext context) {
              return Webpage(
                WebViewModel(widget.itemData['title'], widget.itemData['link']),
                widget.itemData['collect'],
              );
            },
          ),
        );
        setState(() {
          _scale = 1.0;
        });
      },
      onTapCancel: () {
        setState(() {
          _scale = 1.0;
        });
      },
      onTapDown: (details) {
        setState(() {
          _scale = 0.9;
        });
      },
      child: AnimatedScale(
        scale: _scale,
        duration: Duration(milliseconds: 200),
        child: Card(
          ///阴影效果
          elevation: 4.0,
          child: column,
        ),
      ),
    );
  }
}
